<?php echo $this->headScript();?>
<?php echo $this->headLink();?>
<?php echo $this->partial('resume/menu-add-resume.phtml', array('step' => 'expectation', 'resumeId' => $this->resumeId));?>
<form id="form" action="/resume/save-expectation" method="post">
<div class="from-add-01">
	<h2>Expectation</h2>
	<ul>
		<li>
			<label>Current Salary</label>
			<input type="text" name="current_salary" id="current_salary" value="<?php echo $this->expectationRowSet->getCurrentSalary();?>"/> USD
		</li>
		<li>
			<label>Expected Salary</label>
			<input type="text" name="estimated_salary_from" id="estimated_salary_from" value="<?php echo $this->expectationRowSet->getEstimatedSalaryFrom();?>"/> 
            <input type="text" name="estimated_salary_to" id="estimated_salary_to" value="<?php echo $this->expectationRowSet->getEstimatedSalaryTo();?>"/> USD
		</li>
		<li>
			<label>Expected Location</label>
			<input class="province" type="text" name="province" value="" />
            <div class="multiselect" style="display:none; position:absolute; margin-left:170px">
				<div style="width:160px; float:left">
				<?php 
				$i = 1;
				$checked = '';
				foreach($this->listProvince as $province) :
					if($i % 22 == 0): echo '</div><div style="width:160px; float:left">';endif;
					if(in_array($province['province_id'], $this->resumeProvince, true)) $checked = "checked";
					else $checked = '';
				?>
					<label><input type="checkbox" name="option[]" value="<?php echo $province['province_id']?>" <?php echo $checked;?>/> <?php echo $province['name']?></label>
						
				<?php 
				$i++;
				endforeach;?>
            	</div>
           </div>
		</li>
		<li>
			<label>&nbsp;</label>
			<hr style="width:530px" />
		</li>
		<li>
			<label>Note: </label>
			<textarea name="note" id="note" style="height:100px; width:520px"><?php echo $this->expectationRowSet->getNote();?></textarea>
		</li>
		<li>
			<label>&nbsp;</label>
			<div class="actions">
				<input type="hidden" name="resume_id" id="resume_id" value="<?php echo $this->resumeId; ?>" />
				<input type="hidden" name="expecid" id="expecid" value="<?php echo $this->expectationRowSet->getResExpectationId();?>" />
				<a style="text-decoration:none;" href="/resume/experience/id/<?php echo $this->resumeId; ?>"><input type="button" class="button02" name="button" value="Back" /></a>
				<input type="submit" class="button01" name="button" value="Complete" />
				<a href="#review_resume" style="text-decoration:none;"  class="review_resume">
                    <input type="button" class="button01" name="button" value="Review" />
                </a>
			</div>
		</li>
	</ul>
</div>
</form>
<div id="review_resume" style="width:700px;height: 450px; overflow-y:scroll; display: none;">&nbsp;</div>
<script>
$(document).ready(function(){
    $(".province").click(function(){
        if(($(".multiselect").css('display')) == 'none') $(".multiselect").show('slow');
    });

    
    //Begin View detail candidate
    $(".review_resume").fancybox();
    $(".review_resume").click(function(){
        //checkLogin();
        var estimated_salary_to = $('#estimated_salary_to').val();
        var estimated_salary_from = $('#estimated_salary_from').val();
        var current_salary = $('#current_salary').val();
        var note = $('#note').val();
        var resume_id  = $('#resume_id').val();
        var expecid  = $('#expecid').val();
        var button = 'Review';

        var provinces = '';
        var checkboxes = $('input[name="option[]"]:checkbox:checked');
        var provinces = new Array();
        var i=0;
        checkboxes.each(function() {
        	if(provinces) {
                provinces[i] = $(this).val();
                i=i+1;
        	}
        });
        
        $('#review_resume').html('');
        $.ajax({
            url: '/resume/save-expectation',
            type: "POST",
            data: { 
                resume_id: resume_id,
                expecid: expecid,
                estimated_salary_to: estimated_salary_to,
                estimated_salary_from: estimated_salary_from,
                current_salary: current_salary,
                note: note,
                option: provinces,
                button: button
            },
            success: function(result) {
                $('#review_resume').html(result);
            }
        });
    });
    //End View detail candidate
});

//click out to invisible multiselect
$("body").click(function(e){
	var $parentClass = $(e.target).parents('.multiselect');
    if(e.target.className !== "province" && $parentClass.length < 1) {
    	$(".multiselect").hide('slow');
    }       
});

//auto show lable check list in multiselect
var str = '';
$(':checkbox[name^=option]').each(function(){
	if($(this).attr('checked')){
		str = str + $(this).parent().text() + ';';
	} 
});
str = str.slice(0, -1)
$('.province').val(str);

//click chekcbox in mutiselect
$('.multiselect').bind('click', function() {
	var str = '';
	$(':checkbox[name^=option]').each(function(){
		if($(this).attr('checked')){
			str = str + $(this).parent().text() + ';';
		} 
	});
	str = str.slice(0, -1)
	$('.province').val(str);
});

jQuery.fn.multiselect = function() {
    $(this).each(function() {
        var checkboxes = $(this).find("input:checkbox");
        checkboxes.each(function() {
            var checkbox = $(this);
        });
    });
};

$(".multiselect").multiselect();
</script>